﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Code4Public.Settings;

namespace Code4Public.GUI
{
    public partial class ThemeSelectorForm : Form
    {
        private readonly ThemesCollection m_themesCollection = null;
        private readonly bool m_addDefaultTheme = false;

        public ThemeSelectorForm()
        {
            InitializeComponent();
        }

        public ThemeSelectorForm(ThemesCollection themesCollection, bool addDefaultTheme) : this()
        {
            m_themesCollection = themesCollection;
            m_addDefaultTheme = addDefaultTheme;
            InitThemesList();
        }

        private void InitThemesList()
        {
            if (m_addDefaultTheme)
            {
                this.listThemeNames.Items.Add(new Theme("(Default Theme)"));
            }

            if(m_themesCollection != null)
            {
                this.listThemeNames.Items.AddRange(m_themesCollection.ToArray());
            }

            if (listThemeNames.Items.Count > 0)
                listThemeNames.SelectedIndex = 0;
        }

        public static Theme ShowThemeSelectorForm(ThemesCollection themesCollection, bool addDefaultTheme)
        {
            using (var frm = new ThemeSelectorForm(themesCollection, addDefaultTheme))
            {
                if (DialogResult.OK == frm.ShowDialog())
                    return frm.listThemeNames.SelectedItem as Theme;
            }

            return null;
        }

        private void listThemeNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedTheme = listThemeNames.SelectedItem as Theme;
            if (selectedTheme != null)
            {
                themePreviewBox.Theme = selectedTheme;
                themePreviewBox.Refresh();
            }
        }

    }
}
